package com.example.a02back.controller;

import com.example.a02back.common.APIResponse;
import com.example.a02back.dto.FavoriteList;
import com.example.a02back.service.impl.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName QueryController
 * @Description
 * @Author SimpChaos
 * @Date 2022/7/14 16:50
 * @Version 1.0
 **/
@RestController
@Controller
@ResponseBody
@RequestMapping("/query")
public class QueryController {

    @Resource
    private UserServiceImpl userService;
    @Resource
    private TradeServiceImpl tradeService;
    @Resource
    private AuthServicelmpl auth;
    @Resource
    private TopicServiceImpl topicService;
    @Resource
    private CardServiceImpl cardService;
    @Resource
    private FavoriteItemServiceImpl favoriteItem;
    @Resource
    private FavoriteTopicServiceImpl favoriteTopic;

    /**
     * @Description: 得到某个悬赏令的详细信息
     * @Author: SimpChaos
     * @Date: 2022/7/12 16:38
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getOne")
    public APIResponse<?> getOne(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        String sid = httpServletRequest.getParameter("sid");
        return APIResponse.success("SUCCESS",tradeService.getOne(sid));
    }

    /**
     * @Description: 获取悬赏令页面
     * @Author: SimpChaos
     * @Date: 2022/7/14 16:26
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getWList")
    public APIResponse<?> getWantingList(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        return APIResponse.success("SUCCESS",tradeService.getWantList(decode));
    }


    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 7:44
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getRedList")
    public APIResponse<?> getWreDList(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        return APIResponse.success("SUCCESS",tradeService.getRedList());
    }





    /**
     * @Description: 获取商品页面
     * @Author: SimpChaos
     * @Date: 2022/7/14 16:39
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getSList")
    public APIResponse<?> getSellingList(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        Integer type = Integer.parseInt(httpServletRequest.getParameter("type"));
        return APIResponse.success("SUCCESS",tradeService.getSellList(decode,type));
    }


/**
 * @Description:
 * @Author: SimpChaos
 * @Date: 2022/7/15 10:12
 * @Param: [httpServletRequest, httpServletResponse]
 * @Return: com.example.a02back.common.APIResponse<?>
 */
@CrossOrigin
@RequestMapping("/getTopic")
    public APIResponse<?> getTopic(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        String topicid = httpServletRequest.getParameter("aid");
        return APIResponse.success("SUCCESS",topicService.getOne(topicid));
    }


    /**
     * @Description: 获取活络页面
     * @Author: SimpChaos
     * @Date: 2022/7/14 16:39
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getTList")
    public APIResponse<?> getTopicList(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        /**
         *  1为大型比赛，2为文艺演出，3为讲座，4为娱乐活动，5为其他,0为全部
         */
        Integer activeValue = Integer.parseInt(httpServletRequest.getParameter("activeValue"));
        return APIResponse.success("SUCCESS",topicService.getTopicList(decode,activeValue));
    }


    /**
     * @Description: 获得用户自定义的所有身份卡片
     * @Author: SimpChaos
     * @Date: 2022/7/15 11:35
     * @Param:
     * @Return:
     */
    @CrossOrigin
    @RequestMapping("/getCard")
    public APIResponse<?> getCard(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        return APIResponse.success("SUCCESS",cardService.getCard(uid));
    }

/**
 * @Description: 获得当前用户使用的卡片
 * @Author: SimpChaos
 * @Date: 2022/7/15 17:19
 * @Param: [httpServletRequest, httpServletResponse]
 * @Return: com.example.a02back.common.APIResponse<?>
 */
    @CrossOrigin
    @RequestMapping("/getUserCard")
    public APIResponse<?> getUserCard(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        return APIResponse.success("SUCCESS",userService.getUserCard(uid));
    }


    /**
     * @Description:
     * @Author: SimpChaos
     * @Date: 2022/7/15 17:46
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getMydone")
    public APIResponse<?> getMyDone(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        return APIResponse.success("SUCCESS",tradeService.getMyDone(decode,uid));
    }

    /**
     * @Description:
     * @Author: SimpChaos
     * @Date: 2022/7/15 17:48
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getMyPublish")
    public APIResponse<?> getMyPublish(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        return APIResponse.success("SUCCESS",tradeService.getMyPublish(decode,uid));
    }


    /**
     * @Description:
     * @Author: SimpChaos
     * @Date: 2022/7/15 17:48
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/getMyBuy")
    public APIResponse<?> getMyBuy(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        return APIResponse.success("SUCCESS",tradeService.getMyBuy(decode,uid));
    }

/**
 * @Description:
 * @Author: SimpChaos
 * @Date: 2022/7/15 22:02
 * @Param: [httpServletRequest, httpServletResponse]
 * @Return: com.example.a02back.common.APIResponse<?>
 */
    @CrossOrigin
    @RequestMapping("getFavItem")
    public APIResponse<?> getFavItem(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        Integer type = Integer.parseInt(httpServletRequest.getParameter("type"));
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        List<String> list1 = favoriteItem.getFavItem(decode,uid);
        return APIResponse.success("SUCCESS",tradeService.getFavItemList(list1,type));
    }



    /**
     * @Description:
     * @Author: SimpChaos
     * @Date: 2022/7/15 22:02
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("getFavTopic")
    public APIResponse<?> getFavTopic(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        List<String> list1 = favoriteTopic.getFavTopic(decode,uid);
        return APIResponse.success("SUCCESS",topicService.getFavTopicList(list1));
    }

    /**
     * @Description:
     * @Author: SimpChaos
     * @Date: 2022/7/15 22:02
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("getFav")
    public APIResponse<?> getFav(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        String page = httpServletRequest.getParameter("page");
        Long decode = Long.valueOf(page);
        FavoriteList a = new FavoriteList();
        List<String> list1 = favoriteItem.getFavItem(decode,uid);
        List<String> list2 = favoriteTopic.getFavTopic(decode,uid);
        a.setWantList(tradeService.getFavItemList(list2,1));
        a.setSellList(tradeService.getFavItemList(list2,2));
        a.setTopicList(topicService.getFavTopicList(list1));
        return APIResponse.success("SUCCESS",a);
    }


/**
 * @Description:
 * @Author: SimpChaos
 * @Date: 2022/7/15 23:00
 * @Param: [httpServletRequest, httpServletResponse]
 * @Return: com.example.a02back.common.APIResponse<?>
 */
    @CrossOrigin
    @RequestMapping("getMyTopic")
    public APIResponse<?> getMyTopic(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String uid = auth.getUidFromToken(token);
        return APIResponse.success("SUCCESS",topicService.getMyTopic(uid));
    }



}
